using Microsoft.EntityFrameworkCore;
using tafei_thingsapi.Models;
using System.Linq;

namespace tafei_thingsapi
{
    public static class DbInitializer
    {
        public static void Initialize(tafei_thingsapiContext context)
        {
            context.Database.EnsureCreated();

            // 检查是否已有用户数据
            if (context.Users.Any())
            {
                return; // 数据库已存在且有数据
            }

            // 添加默认管理员账号
            var admin = new User
            {
                Id = 1,
                Username = "admin",
                Password = "admin123",
                Role = "admin"
            };

            context.Users.Add(admin);
            context.SaveChanges();
        }
    }
}